# -*- coding:utf-8 -*-

import socket

socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.bind(('192.168.0.12', 8001))
socket.listen(5)
while 1:
    connection, address = socket.accept()
    try:
        connection.settimeout(5)
        buf = connection.recv(1024)
        if buf == '1':
            connection.send('welcome to server!')
        else:
            connection.send('please go away !')
    except socket.timeout:
        print 'time out !'
    connection.close()
